import 'package:flutter/material.dart';

import '../example/index.dart';
import '../example/routes.dart';
import '../pages/about/about.dart';
import '../pages/auth/login.dart';
import '../pages/auth/register.dart';
import '../pages/knowledge/knowledge_detail.dart';
import '../pages/tabber.dart';

class RoutePath {
  static const String home = '/';
  static const String about = '/about';
  static const String example = '/example';
  static const String login = '/login';
}

Map routes = {
  '/': (context) => const Tabber(),
  '/about': (context) => const AboutPage(),
  '/example': (context) => const ExamplePage(),
  '/login': (context) => const Login(),
  '/register': (context) => const Register(),
  '/knowledgeDetail': (context, {arguments}) {
    print(arguments);
    return KnowledgeDetail(arguments: arguments);
  },
  ...exampleRoutes
};


class Routes {
  static Route? onGenerateRoute(RouteSettings settings) {
    final String? name = settings.name;
    final Object? arguments = settings.arguments;
    final Function? pageBuilder = routes[name];
    print(arguments);
    print(pageBuilder);
    if (pageBuilder == null) return null;
    final Route route = MaterialPageRoute(
      builder: (context) => (arguments != null?pageBuilder(context,arguments:arguments):pageBuilder(context))
    );

    return route;
  }
}